using System.Reflection;
using Microsoft.EntityFrameworkCore;
using WebapiTemplate.Domain.Entity;

/// <summary>
/// 数据库上下文
/// </summary>

namespace WebapiTemplate.Infrastructure.Persistence
{
    public class WebapiDbcontext : DbContext
    {
        //为注入数据库依赖提供的构造函数
        public WebapiDbcontext(DbContextOptions<WebapiDbcontext> options) : base(options) { }


        //查找设置表字段的类并启用
        protected override void OnModelCreating(ModelBuilder builder)
        {
            // 应用当前Assembly中定义的所有的Configurations，就不需要一个一个去写了。
            builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());

            base.OnModelCreating(builder);
        }

        public DbSet<User> User => Set<User>(); //public DbSet<User> User { get; set; }
        public DbSet<Role> Role => Set<Role>();
        public DbSet<UserRole> UserRole => Set<UserRole>();
        public DbSet<AuditLog> AuditLog => Set<AuditLog>();
        public DbSet<FileLog> FilesInfo => Set<FileLog>();
        public DbSet<ExceptionLog> ExceptionLog => Set<ExceptionLog>();
        public DbSet<AppIdentityUser> AppIdentityUser => Set<AppIdentityUser>();
    }
}
